﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Media;
using Microsoft.Win32;
using System.Data;

namespace EasyTrader
{
    using PriceSignalList = List<EasyTrader.Signal.PriceSignal>;
    public delegate void SysManagerEventHandler(object sender, SysManagerEventArgs e);

    public class SysManagerEventArgs : EventArgs
    {
        private bool m_AutoOrder = false;
        public bool AutoOrder
        {
            get { return m_AutoOrder; }
            set { m_AutoOrder = value; }
        }
        private int m_SysType = -1;
        public int SysType
        {
            get { return m_SysType; }
            set { m_SysType = value; }
        }

        public SysManagerEventArgs(bool a_AutoOrder, int a_SysType)
        {
            m_AutoOrder = a_AutoOrder;
            m_SysType = a_SysType;
        }
    }


    static class GlobalVar
    {
#region Data Download Enable Variables
        public static int CmeDailyRefCount = 0;
        public static int CmeMstRefCount = 0;
        public static int CpFore8312RefCount = 0;
        public static int CpSvr8300RefCount = 0;
        public static int OpChartRefCount = 1;
        public static int StockChartRefCount = 0;
        public static int OpTodayRefCount = 0;
#endregion
#region Option Variables


        public static EasyTrader.Option.CompVal OPNVAL = new EasyTrader.Option.CompVal();

        public static int BackRefRange = 4;

        public static int StateNone = 0;
        public static int StateHighInv = 1;
        public static int StateLowInv = 2;
        public static int StateHighDiv = 3;
        public static int StateLowDiv = 4;

        public static int CenterTryCount = 1;
        public static double CenterER = 0.1;

        public static string K200Dir = "C:\\Kospi200.txt";

        public static int ModeHigh = 1;
        public static int ModeLow = -1;
        public static double ErrorRange = 0.05;
        public static double HeightGap = 0.5;
        public static double FutErrorRange = 0.15;
        public static double OptErrorRange = 0.1;

        public static int OrderTargetFuture = 1;
        public static int OrderTargetOption = 2;
        public static bool FirstCallGot = false;
        public static bool FirstPutGot = false;

        public static int OpSignalHighBeginMP = 1; // 시가가 고가로 시작함
        public static int OpSignalLowBeginMP = -1; // 시가가 저가로 시작함
        public static int OpSignalHighBeginMH = 2; // 시가가 고가로 시작함
        public static int OpSignalLowBeginMH = -2; // 시가가 저가로 시작함
        public static int OpSignalHighBeginGP = 3; // 시가가 고가로 시작함
        public static int OpSignalLowBeginGP = -3; // 시가가 저가로 시작함
        public static int OpSignalHighBegin = 4; // 시가가 고가로 시작함
        public static int OpSignalLowBegin = -4; // 시가가 저가로 시작함


        public static int OpSignalOverHigh = 4; // 고가를 넘어서 버림
        public static int OpSignalUnderLow = -4; // 저가를 넘어서 버림

        public static int OpSignalNone = 0;
        public static int OpSignalBreakDownEnter = -1;
        public static int OpSignalBreakUpEnter = 1;
        public static int OpSignalBreakDownLiq = -3; // 붕괴로 인한 청산
        public static int OpSignalBreakUpLiq = 3; // 돌파로 인한 청산
        public static int OpSignalUpLiq = 2; // 올라가면서 청산
        public static int OpSignalDownLiq = -2; // 내려가면서 청산
        public static int OpSignalResist = -4; // 저항으로 인한 청산
        public static int OpSignalSupport = 4; // 지지로 인한 청산
        public static int OpSignalBendHigh = -5; // 저항으로 인한 청산
        public static int OpSignalBendLow = 5; // 지지로 인한 청산

        public static int OpSignalCallBendHigh = -6; // 저항으로 인한 청산
        public static int OpSignalCallBendLow = 6; // 지지로 인한 청산

        public static int OpSignalPutBendHigh = -7; // 저항으로 인한 청산
        public static int OpSignalPutBendLow = 7; // 지지로 인한 청산

        public static int OpSignalMode = 0;
        public static int OpSignalModeBreakUp = 1; // 돌파하는 입장에서 조사한다. 돌파는 긍정 붕괴는 부정
        public static int OpSignalModeBreakDown = -1; // 붕괴하는 입장에서 조사한다. 붕괴는 긍정 돌파는 부정
        public static int OpSignalModeNone = 0;
        public static int OpCallPutModeNone = 0;
        public static int OpCallMode = 1;
        public static int OpPutMode = -1;
        public static int FromUp = -1;
        public static int FromDown = 1;
        public static int FromNone = 0;
        public static int OptChartRange = 3;
        public static int OpCodeCount = 6;
        public static string CATM = "";
        public static string PATM = "";
        public static double MinOpDelta = 0.15;
        public static double[] m_OpConstPriceList = new double[12] { 1.20, 1.80, 2.50, 3.0, 3.5, 4.0, 4.4, 4.85, 5.0, 6.85, 7.1, 8.1 };

        public static double[] OpMainPrice = new double[6] { 1.20, 2.50, 3.5, 4.85, 5.2, 6.85};

        public static int BreakNone = 0;
        public static int BreakDown = -1; // 뚫고 내려감
        public static int BreakUp = 1; // 뚫고 올라옴
        public static int BreakUpFromDown = 6; // 붕괴후 돌파
        public static int BreakDownFromUp = -6; // 돌파 후 붕괴
        public static int Resist = -3;
        public static int Support = 3;
        public static int LiqDown = -2; // 내려가면서 청산됨
        public static int LiqUp = 2; // 올라오면서 청산됨
        public static int NoneRange = 0; // 초기 상태는 범위가 없음.
        public static int InRange = 3; // 초기 상태가 범위 안에 있음
        public static int UpRange = 4; // 초기 상태가 범위 위에 있음
        public static int DownRange = -4; // 초기 상태가 범위 아래에 있음

        public static int InUpRange = 5; // 초기 상태가 범위 위에 있음
        public static int InDownRange = -5; // 초기 상태가 범위 아래에 있음


        public static int FromUpDownStateNone = 0;
        public static int FromUpDownStateIn = 1;

        public static bool OptValMonthLow = true;
        public static bool OptValLowTarget = true;
        public static bool OptValBase = true;
        public static bool OptValHighTarget = true;
        public static bool OptValMonthHigh = true;
        public static int HighTarget = 1;
        public static int LowTarget = -1;

        public static string GetOppositeCode(string a_OpCode)
        {
            string sideCode = a_OpCode.Substring(0, 1);
            string leftCode = a_OpCode.Substring(1, a_OpCode.Length - 1);
            string resultCode = "";
            if (sideCode == "2")
            {
                resultCode = "3";
            }
            else if (sideCode == "3")
            {
                resultCode = "2";
            }

            resultCode += leftCode;

            return resultCode;
        }
#endregion
#region Stock Code Name
        public static string[] m_WorldCodeTable = new string[6] { ".DJI", "SPX", "COMP", "GB#FTSE", "GR#DAX", "FR#CAC" };
        public static string[] m_StockCodeTable = new string[10] { "A005930", "A005830", "A005490", "A012330", "A000270", "A032830", "A015760", "A000660", "A005935", "A055550"};
        public static string[] m_MoneyExCodeTable = new string[1] { "FX@KRW" };
#endregion
#region Liquid Sys Var
        
#endregion
#region Multi System

        public static string[] SysNameArray = new string[16] { "지수호가종합", "지수파동", "호가파동", "호가공간점유율", "호가정점", "콜풋공간점유율", "순수호가정점", "5분호가정점", "콜풋수렴발산", "끝점공략", "옵션가격", "옵션주요가격", "중마중목", "양매도", "꺽기", "주체별" };

        public static double MaxLossMargin = 0.5;
        public static int CallPutRefRange = 4;
        public static int CallPutAveVal = 3;

        public static string SysName0 = "지수호가종합";
        public static string SysName1 = "지수파동";
        public static string SysName2 = "호가파동";
        public static string SysName3 = "호가공간점유율";
        public static string SysName4 = "호가정점";
        public static string SysName5 = "콜풋공간점유율";



        public static int SysTypeJisuWaveHogaSummit = 0;
        public static int SysTypeJisuWave = 1;
        public static int SysTypeHogaWave = 2;
        public static int SysTypeHogaSquareOcc = 3;
        public static int SysTypeHogaSummit = 4;
        public static int SysTypeCallPutSquareOcc = 5;
        public static int SysTypePureHogaSummit = 6;
        public static int SysTypeLooseHogaSummit = 7;
        public static int SysTypeCallPutInvDiv = 8;
        public static int SysTypeTipAttack = 9;
        public static int SysTypeOptPrice = 10;

        public static int SysTypeOptMainPrice = 11;
        public static int SysTypeOptCenterPrice = 12;
        public static int SysTypeOptBothSell = 13;
        public static int SysTypeOptBend = 14;
        public static int SysTypeSubject = 15;


        public static int AcceptBuySell = 0;
        public static int AcceptBuyOnly = 1;
        public static int AcceptSellOnly = 2;

        public static int FirstSigByHogaAngle = 0; // 호가 각도
        public static int FirstSigByJisu = 1; // 지수 높이
        public static int FirstSigByHogaDelta = 2; // 호가 차이 비율
        public static int FirstSigByWaveCount = 3; // 파동 순서
        public static int FirstSigByHogaAngleNHeight = 4; // 호가각도와 지수 높이
        public static int FirstSigByHogaDeltaNHeight = 5; // 호가 차이 비율과 지수 높이
        public static int FirstSigByWaveCounNHeight = 6; // 파동순서와 지수 높이

        public static int HogaJisuSysFirstSigType = FirstSigByHogaAngle;
        public static int HogaSysFirstSigType = FirstSigByHogaAngle;
        public static int JisuSysFirstSigType = FirstSigByHogaAngle;
        public static int SquarOccSysFirstSigType = FirstSigByHogaAngle;

        public static double FirstMinHeight = 0.15;
        public static double FirstMinAngle = 30.0;
        public static double FirstMinPercent = 0.7;
        public static int FirstWave = 2;
        public static int FirstHoga = 500;
        public static int InvMinHogaDelta = 400;
        public static int DivMinHogaDelta = 300;
        public static bool FirstSignalByClose = true;

        public static int MinTimeOcc = 20;
        public static int MinSquareOcc = 5;
        public static int MaxSquareOcc = 20;
        public static int MidSquareOcc = 10;
        public static int MaxTimeOcc = 90;

        public static int LiquidMaxHoga = 3300;
        public static int LiquidMidHoga = 2900;
        public static int LiquidMinHoga = 2700;

        public static int OneWayMinTimeOcc = 90;
        public static int OneWayMinSquareOcc = 5;
#endregion
#region ShortWave Getting Def
        public static double HighLowRange = 0.1;
        public static int PosHigh = 1;
        public static int PosMid = 2;
        public static int PosLow = 3;
        public static int PosNone = 0;
        public static int HighToMid = 1;
        public static int LowToMid = 2;
        public static int MidToHigh = 3;
        public static int MidToLow = 4;
        public static int HighToLow = 5;
        public static int LowToHigh = 6;
        public static int TrendNone = 0;
#endregion
#region Producer Info
        public static string Name = "Shiwan Sung";
        public static string HP = "010-3796-9128";
        public static string EMail = "pieangel@naver.com";
        public static string CreditMsg = "이 프로그램은 아래사람에게 저작권이 있으며, 허락없이 사용하는 것은 불법입니다. \n 문의사항이 있으면 아래로 연락주세요.";
        public static string CopyWriteMsg = "이 프로그램은 사용기간이 끝났습니다. 사용기간 연장을 원하시면 아래로 연락주세요.";
        public static int YearLimit = 2013;
        public static int MonthLimit = 12;
        public static int DayLimit = 30;
#endregion
#region Hoga Signal Settings
        public static double MinHogaAngleDelta = 15.0;
        // 장초 5분동안의 호가 참조 범위
        public static int HogaInitRefRange = 3;

        public static double MinHogaAngle = 15.0;
        public static int BuySellBeginRefRange = 5;
        public static int BuySellRefRange = 7;
        public static double MinHogaSignalHeight = 500.0;
        public static int MinHogaLimit = 200;
        public static int HogaValRefRange = 3;
        public static int MinHogaAveReferance = 3;
        public static int MinHogaAveVal = 2;
        public static int BuySellPower = PowerNone;
        public static int PowerBuy = 1;
        public static int PowerSell = 2;
        public static int PowerNone = 0;
       
        public static int MiddleSquareOcc = 50;
        public static int LargeSquareOcc = 80;
        // 최대 호가 청산 한계값 - 이 값이 넘으면 무조건 청산을 적용한다.
        public static int MaxHogaLiquidLimit = 2700;
        // 최소 호가 청산 한계값 - 최소한 시작가에 이값을 더한 값을 넘어야 수렴청산을 적용할수 있다.
        public static int MinHogaLiquidLimit = 1000;
        // 신호 평균 참조값
        public static int HogaSignalRefRange = 10;
        // 신호 보호 높이값 - 선형회귀 값이 이 값을 넘지 않으면 신호를 발생하지 않는다.
        public static double MinHogaSignalRegHeight = 0.1;
        public static double MinHogaFirstMinHeight = 0.1;
        // 많은 쪽 퍼센트에 따라 증가하는 최대 청산 건수 : 가장 낮은 값(MinHogaLiquidLimit)에서 시작한다.
        public static int HogaIncUnit = 200;
#endregion
        #region Liquid Definition
        public static int LiquidByPercent = 0;
        public static int LiquidByPrice = 1;
        public static int LiquidByBoth = 2;
        public static bool LiquidApply = false;
        // 0 : 퍼센트, 1 : 값, 2 : 둘다 적용
        public static int LiquidMethod = LiquidByPercent;
        public static double LiquidPercent = 0.2;
        public static double AutoProfitStopPrice = 0.0;
        public static double AutoLossStopPrice = 0.0;
        public static double LossStopAll = 50;
        public static double ProfitStopAll = 60;
        public static bool LiquidApplyAll = true;
        #endregion
        #region System Message
        public static string StateMessage = "시스템을 준비중입니다. 잠시만 기다려 주세요.";
        public static string ManualOrderWarnMsg = "수동 주문은 시스템운영창의 자동주문을 해제해야 가능합니다.";
        public static string SimulationModeWarnMsg = "모의모드가 아닙니다. 설정->운영설정에서 운영모드를 모의모드로 변경한 후에 프로그램을 종료후 다시 시작해 주세요.";
        public static string OperationChangedWarnMsg = "운영모드를 변경했습니다. 프로그램을 다시 시작해 주세요.";
        public static string OrderEndedMsg = "모든 주문이 청산되었습니다.";
        public static string DirWarnMsg = "디렉토리가 없습니다. 디렉토리를 확인해 주세요.";
        public static string TimeFormatError = "시간 형식이 맞지 않습니다.";
        public static string SimulOrderMessage = "주문없음";
        #endregion
        #region Signal Source Settings
        public static bool KospiForeignPersonEnable = true;
        public static bool KospiOrganPersonEnable = true;
        public static bool FutureForeignEnable = true;
        public static bool OptionPersonCallPutEnable = true;
        public static bool KospiProgramEnable = true;
        public static bool HogaBuySellEnable = true;
        public static bool HogaBidAskEnable = true;
        public static bool WaveEnable = true;
        public static bool ForecastEnable = true;
        public static bool HighLowEnable = true;
        public static bool WorldEnable = true;

        public static bool DJIEnable = true;
        public static bool NASDAQEnable = true;
        public static bool SNP500Enable = true;
        public static bool FTSEEnable = true;
        public static bool DAXEnable = true;
        public static bool CACEnable = true;
        #endregion
        #region Order Settings
        /*
         * 1 : 지정가
         * 2 : 시장가
         * 3 : 조건부지정가
         * 4 : 최유리지정가
         */
        public static int OrderType = 2;
        /*
        0 : 없음
        1 : IOC
        2 : FOK
        */
        public static int OrderCond = 0;
        // 1회 자동 주문 개수
        public static int AutoOrderAmount = 1;
        // 수수료
        public static double Fare = 0.2;
        // 슬리피지
        public static double Slipage = 0.0;
        public static int RemainBuy = 2;
        public static int RemainSell = 1;
        public static int RemainNone = 0;
        public static int OrderBuy = 2;
        public static int OrderSell = 1;
        public static int OrderNone = 0;
        public static bool AutoOrderEnabled = false;
        public static int OrderStartHour = 9;
        public static int OrderStartMin = 0;
        public static int OrderEndHour = 14;
        public static int OrderEndMin = 59;
        public static int OrderStartSignal = 1;
        // 
        public static int OrderEndSignal = 5;
        public static bool ProfitLiquidApply = false;
        public static bool LossLiquidApply = false;
        public static bool PerProfitLiquidApply = false;
        public static bool PerLossLiquidApply = false;

        #endregion
        #region GlobalVar
        public static EasyTrader.ETDataSet GDataSet = null;
        // 전체 신호 관리자를 생성한다.
        public static EasyTrader.Signal.TotalSignalManager GlobalSignalManager = null;
        public static int ProgressVal = 100;
        public static double DayHeight = 0.0;
        public static double DayHigh = 0.0;
        public static double DayLow = 0.0;
        // 현재의 종가를 항상 여기에 넣어 준다.
        public static double CurClose = 0.0;
        public static int FunctionNum = 17;
        public static bool DownloadLock = false;
        public static bool WorldCurDownloaded = true;
        public static double DailyGap = 0.0;
        public static bool AllDataDownloaded = false;
        public static double ReverseRatio = 0.0;
        #endregion
        #region Signal Limit Settings
        public static bool EnableHogaSummitSignal = true;
        // 최대 호가 건수 차이
        public static int MaxDeltaBuySell = 1000;
        // 최대 호가 잔량 차이
        public static int MaxDeltaBidsAsks = 6000;
        // 최소 호가 건수 차이
        public static int MinDeltaBuySell = 250;
        // 최소 호가 잔량 차이
        public static int MinDeltaBidsAsks = 2000;
        // 2575 적용 최소 높이
        // 기준파 신호 적용 가능한 최소 높이
        public static double SignalWaveHeight = 1.2;
        // 기준파가 되기 위한 최소 높이
        public static double MinSignalWaveHeight = 0.2;
        // 신호발생 최소 퍼센트
        public static double MinSignalPercent = 20.0;
        public static double MaxSignalPercent = 70.0;
        public static double MinPriceAngle = 15.0;
        public static double PriceAngle = 0.0;
        // 100%에서 가질 수 있는 각도
        public static double PriceFullAngle = 80.0;
        // 기준파 신호금지 퍼센트
        public static double StandardWaveHighLowPercent = 0.25;
        public static double MinFirstSignalPercent = 14.0;
        public static double MinEntrySignalPercent = 70.0;
        // 신호 발생 최소 각도
        public static double MinSignalAngle = 10.0;
        public static double MaxDailyGap = 2.0;
        // 신호에 반응할 최소한의 높이
        public static double MinHighLowHeight = 0.35;
        public static double MaxHighLowHeight = 1.2;
        public static double MinHighLowPercent = 0.25;
        public static double MinClosePercent = 0.05;
        public static double MaxCloseHeight = 1.2;
        public static double MinCloseHeight = 0.2;
        public static double MinForeInfoHeight = 0.1;
        public static double MinCorrectForeInfoHeight = 0.15;
        public static int MinForeInfoLen = 1;
        public static int MaxForeInfoLen = 60;
        public static double MaxForeInfoHeight = 0.2;
        // 예측파동 시작시간 보정값
        public static int ForecastCompLen = 4;
        public static double MinSignalHeight = 0.5;
        public static double MinHighLowTransHeight = 0.45;
        public static double MinCloseTransHeight = 0.25;

        public static double OneWayMinPercent = 0.4;
        public static int OneWayMinDivLen = 30;
        public static int OneWayMinDeltaBidAsk = 20000;
        public static int OneWayMinDeltaBuySell = 750;

        //public static bool MinSignalPercentEnable = true;
        //public static bool MinEntrySignalPercentEnable = true;
        //public static bool MinFirstSignalPercentEnable = true;
        public static bool MinDeltaBuySellEnable = true;
        public static bool MinDeltaBidsAsksEnable = true;
        public static bool MaxDeltaBuySellEnable = true;
        public static bool MaxDeltaBidsAsksEnable = true;
        public static double CloseCompVal = 0.05;
        public static int MinSignalInterval = 60;
        // 호가 건수를 기반으로 하는 신호 설정값
        public static int MinHogaSignalLimit = 2000;
        // 두개의 값 중 더 낮거나 높은 값을 취함
        public static int MinHogaSignalRealVal = 250;
        public static int MinHogaSignalAverageVal = 150;
        public static double CorrectWaveHeightLimit = 0.6;
        public static double SignalWaveHeightLimit = 0.15;
        public static double WaveRootLimit = 0.05;
        #endregion
        #region ChartSettings
        public static int CPSvrNew7221ChartBaseVal = 0;
        #endregion
        #region Data Download Settings
        public static bool CmeCurrDataDownloaded = false;
        public static bool CmeMstDataDownloaded = false;
        public static bool CPConclusionDataDowanloaded = false;
        public static bool CPSvr8111SDataDownloaded = false;
        public static bool CPSvrNew7221DataDownloaded = false;
        public static bool CPSvrNew7221SKospiDataDowanloaded = false;
        public static bool CPSvrNew7221SFutureDataDowanloaded = false;
        public static bool CPSvrNew7221SOptionDataDowanloaded = false;
        public static bool FutOptChartDataDownloaded = false;
        public static bool FutureCurOnlyDataDownloaded = false;
        public static bool FutureJpBidDatadownloaded = false;
        public static bool FutureMstDataDownloaded = false;
        public static bool StockChartDataDownloaded = false;
        public static bool Cp8312DataDownloaded = false;

        public static bool DJIDataDownloaded = false;
        public static bool NASDAQDataDownloaded = false;
        public static bool SNP500DataDownloaded = false;
        public static bool FTSEDataDownloaded = false;
        public static bool DAXDataDownloaded = false;
        public static bool CACDataDownloaded = false;
        public static bool CmeDailyDataDownloaded = false;
        public static bool FutOptDailyDataDownloaded = false;
        public static int DailyDataCount = 40;
        #endregion
        #region Predefined Chart Type
        // 0 : 봉차트, 1 : 종가선 차트
        public static int FutOptChartType = 1;
        public static int FutureMstChartType = 1;
        public static int FutureCurOnlyChartType = 1;
        public static int CmeCurrChartType = 1;
        public static int CmeMstChartType = 1;
        public static int StockChartType = 1;
        public static int SimulationChartType = 1;
        public static int FutureSystemChartType = 1;
        public static int WorkDate = 0;
        public static int CmeDailyChartType = 0;
        public static int WorldCurChartType = 0;
        #endregion
        #region Operation Settings
        public static bool EnableSound = true;
        public static string OrderState = "주문없음";
        /*
        1 : 지정가[default]
        2 : 시장가
        3 : 조건부지정가
        4 : 최유리지정가
         */

        public static string ServerOrderMsg = "주문이 없습니다.";
        // 현재 주식 종목
        public static string StockCode = "A005930";
        public static object FutureCode = "";
        public static int OperationModeNormal = 0;
        public static int OperationModeSimul = 1;
        //public static int OperationModeOpSimul = 2;
        public static int SimulIndex = 0;
        // 운영 모드 0 : 정상모드, 1 : 시뮬레이션 모드
        public static int OperationMode = OperationModeNormal;
        public static int MaxDayIndex = 365;
        public static int MaxNightIndex = 660;
        public static bool EnableOrder = false;
        public static int DayCloseHour = 15;
        public static int DayCloseMin = 16;
        public static int DayOpenMin = 0;
        // 주문창에서 보이는 최대 가격의 개수
        public static int ShowMaxPriceNumber = 240;
        public static int DayOpenTime = 9;
        public static int NightOpenTime = 18;
        public static string RegressionType = "Linear";
        public static int ReferenceRange = 15;
        public static bool AutoOrder = false;
        public static int ForecastLength = 10;
        public static int MainTimerInterval = 1000; // Millisecond
        public static int SubTimerInterval = 3000; // Millisecond
        // 신호 산출 방법 : 종합(0), 기준파(1)
        public static int SignalMethod = 0;
        public static int SubjectSelection = 0;
        public static bool SaveEveryMinute = false;
        public static bool OptionExtremeCase = false;
        public static bool FirstSignalFilter = false;
        public static bool AfterFirstSignalFilter = false;
        public static int PriceReferenceRange = 10;
        // 신호전환방법 : 0 : %로 , 1 : 값으로
        public static int SignalTransMethod = TransSignalByPercent;
        public static int TransSignalByPercent = 0;
        public static int TransSignalByVal = 1;
        // 호가 중간값 산출을 위한 값 참조 범위
        public static int HogaReferenceRange = 5;
        #endregion
        #region Signal Const
        public static int SignalBuy = 1;
        public static int SignalSell = -1;
        public static int SignalExitBuy = -2;
        public static int SignalExitSell = 2;
        public static int SignalNone = 0;
        public static int SignalLiquidNBuy = 3;
        public static int SignalLiquidNSell = -3;
        public static int SignalBuyLiquid = -4;
        public static int SignalSellLiquid = 4;
        public static int SignalBuyPartialLiquid = -5;
        public static int SignalSellPartialLiquid = 5;

        // 봉신호를 받기 위한 최소 높이
        public static double MinBarHeight = 0.25;
        // 청산 신호를 내기 위한 최소 호가 건수
        public static int MinBuySell = 3300;
        // 청산 신호를 내기 위한 최소 호가 잔량
        public static int MinBidAsk = 16000;
        // 2575% 값
        public static double HighLowPercent = 0.25;
        // 신호 결정 요소의 개수
        // 1. 개인-외국인
        // 2. 개인-기관
        // 3. 개인옵션 콜-풋
        // 4. 호가 잔량
        // 5. 호가 건수
        // 6. 프로그램 매매 경향
        // 7. 예측 지수 방향
        // 8. 파동의 방향
        // 9. 외국인 선물 방향
        // 10. 봉신호 - 봉신호는 청산이나 방향전환에서만 사용한다.
        public static double PricePerMin = 55.65;
        public static double HogaBuySellPerMin = 23.2;
        public static double HogaBidsAsksPerMin = 192;
        public static double KospiPerMin = 7.5;
        public static double ProgramPerMin = 4.2;
        public static double OptionPerMin = 0.4;
        public static double FuturePerMin = 12.84;
        public static int SignalEndHour = 14;
        public static int SignalEndMin = 59;
        public static int SignalStartHour = 9;
        public static int SignalStartMin = 0;
        public static int SignalStateNone = 0;
        // 진입신호
        public static int SignalStateEntry = 1;
        // 첫신호
        public static int SignalStateFirst = 2;
        // 전환신호
        public static int SignalStateTrans = 3;
        // 돌파신호
        public static int SignalStateOver = 4;
        // 청산신호
        public static int SignalStateLiquid = 5;
        // 수정신호
        public static int SignalStateCorrect = 6;
        public static int WaveType = WaveTypeNone;
        public static int WaveTypeNone = 0;
        public static int WaveTypeBuy = 1;
        public static int WaveTypeSell = 2;
        #endregion
        #region Wave Const
        // 가격 상승
        public static int PriceUp = 1;
        // 가격 하락
        public static int PriceDown = -1;
        // 가격 횡보
        public static int PriceFlat = 0;
        public static int WaveFit = 1;
        public static int WaveUnFit = 0;
        public static int FirstAveFilterVal = 2;
        public static int SecondAveFilterVal = 2;
        // 신호를 만들수 있는 최소한의 파동 높이
        // 이 높이 이하에서는 신호를 만들지 않는다.
        public static double SignalMinWaveHeight = 0.7;
        // 방향 전환을 위한 최소한의 퍼센트
        public static double SignalTransMinPercent = 0.15;
        // 파동 최소 시간 길이
        public static int WaveLenLimit = 1;
        // 파동 최소 높이
        public static double WaveHeightLimit = 0.2;
        #endregion
        #region CPTableColumn Size
        public static int CmeCurrTableColSize = 11;
        public static int CmeMstTableColSize = 11;
        public static int CPConclusionTableColSize = 15;
        public static int CPSvr8111STableColSize = 10;
        public static int CPSvrNew7221TableColSize = 18;
        public static int CPSvrNew7221SKospiTableColSize = 16;
        public static int CPSvrNew7221SFutureTableColSize = 6;
        public static int CPSvrNew7221SOptionTableColSize = 9;
        public static int FutOptChartTableColSize = 11;
        public static int FutureCurOnlyTableColSize = 12;
        public static int FutureJpBidTableColSize = 39;
        public static int FutureMstTableColSize = 12;
        #endregion
        #region CPObject Timer Settings
        public static int TimerGap = 300; // Milisecond
        public static bool FutureMstStarted = false;
        public static bool FutOptChartStarted = false;
        public static bool CPSvrNew7221Started = false;
        public static bool StockChartStarted = false;
        public static bool CmeMstStarted = false;
        public static bool DataFetchStarted = false;

        public static bool FutOptChartTimerAutoStart = true;
        public static bool FutureMstTimerAutoStart = true;
        public static bool CmeMstTimerAutoStart = true;
        public static bool CPSvrNew7221TimerAutoStart = true;
        public static bool SubscribeDataTimerAutoStart = true;

        public static int FutOptChartTimerInterval = 2;
        public static int FutureMstTimerInterval = 2;
        public static int CmeMstTimerInterval = 2;
        public static int CPSvrNew7221TimerInterval = 4;
        public static int StockChartTimerInterval = 10;
        public static int SubscribeDataTimerInterval = 10; // 밀리초임
        public static int DataFetchTimerInterval = 2;

        public static bool CmeCurrEnabled = false;
        public static bool CPSvr8111SEnabled = true;
        public static bool CPSvrNew7221SEnabled = true;
        public static bool FutureJpBidEnabled = true;
        public static bool FutureCurOnlyEnabled = true;

        public static bool FutOptChartEnabled = true;
        public static bool CPSvrNew7221Enabled = true;
        public static bool FutureMstEnabled = true;
        public static bool CmeMstEnabled = true;

        public static bool SubscribeDataEnabled = true;
        public static int ChartRefreshInterval = 100;
        #endregion
        #region Global Functions

        public static bool GetOHLC(DataTable a_Table, int a_CurIndex, out double a_Open, out double a_High, out double a_Low, out double a_Close)
        {
            a_Open = 0.0;
            a_High = 0.0;
            a_Low = 0.0;
            a_Close = 0.0;
            // 테이블 목록의 인덱스를 찾아 그 값을 저장해 준다.
            int rowCount = a_Table.Rows.Count;
            if (rowCount == 0)
                return false;
            int index = a_CurIndex;
            if (index < 0)
                index = 0;
            if (index > rowCount - 1)
                index = rowCount - 1;

            DataRow row = a_Table.Rows[index];

            a_Close = Convert.ToDouble(row["종가"]);
            a_Open = Convert.ToDouble(row["시가"]);
            a_High = Convert.ToDouble(row["고가"]);
            a_Low = Convert.ToDouble(row["저가"]);


            return true;
        }

        public static int FindInvDiv(int a_CurIndex, DataTable a_Table, ref double a_Min, ref double a_Max, ref double a_Close, int a_Mode)
        {
            int state = GlobalVar.StateNone;

            int highIndex = 0;
            int lowIndex = 0;
            int recentIndex = 0;
            double high = 0.0, low = 0.0, open = 0.0;
            recentIndex = FindHighLowIndex(a_Table, a_CurIndex - GlobalVar.BackRefRange, a_CurIndex, ref highIndex, ref lowIndex, ref a_Min, ref a_Max, ref open, ref a_Close, ref low, ref high);

            if (recentIndex >= 0)
            {
                int minIndex = Math.Min(highIndex, lowIndex);
                if (minIndex == 0)
                {
                    double firstOpen = 0.0, firstHigh = 0.0, firstLow = 0.0, firstClose = 0.0;
                    GetOHLC(a_Table, a_CurIndex, out firstOpen, out firstHigh, out firstLow, out firstClose);
                    if (minIndex == highIndex)
                    {
                        if (a_Mode == GlobalVar.PriceDown)
                        {
                            if (firstOpen == firstHigh)
                            {
                                if (a_Close < firstOpen - GlobalVar.ErrorRange)
                                {
                                    // high inverse
                                    state = GlobalVar.StateHighInv;
                                }
                            }
                            else if (Math.Abs(firstHigh - firstOpen) <= GlobalVar.FutErrorRange)
                            {
                                if (a_Close < firstOpen - GlobalVar.ErrorRange)
                                {
                                    // high inverse
                                    state = GlobalVar.StateHighInv;
                                }
                            }
                        }
                    }
                    else if (minIndex == lowIndex)
                    {
                        if (a_Mode == GlobalVar.PriceUp)
                        {
                            if (firstOpen == firstLow)
                            {
                                if (a_Close > firstOpen + GlobalVar.ErrorRange)
                                {
                                    // low inverse
                                    state = GlobalVar.StateLowInv;
                                }
                            }
                            else if (Math.Abs(firstLow - firstOpen) <= GlobalVar.FutErrorRange)
                            {
                                if (a_Close > firstOpen + GlobalVar.ErrorRange)
                                {
                                    // low inverse
                                    state = GlobalVar.StateLowInv;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (a_Mode == GlobalVar.PriceDown) // 하락 모드 - 저점 수렴을 확인한다.
                    {
                        if (recentIndex == lowIndex)
                        {
                            string range = (a_Max + GlobalVar.ErrorRange).ToString("F2");
                            double rangeVal = Convert.ToDouble(range);
                            if (a_Close >= rangeVal)
                            {
                                // low inverse
                                state = GlobalVar.StateLowInv;
                            }
                        }
                    }
                    else if (a_Mode == GlobalVar.PriceUp) // 상승 모드 - 고점 수렴을 확인한다.
                    {
                        if (recentIndex == highIndex)
                        {
                            string range = (a_Max - GlobalVar.ErrorRange).ToString("F2");
                            double rangeVal = Convert.ToDouble(range);
                            if (a_Close <= rangeVal)
                            {
                                // high inverse
                                state = GlobalVar.StateHighInv;
                            }
                        }
                    }
                }
            }

            return state;
        }

        public static int FindHighLowIndex(DataTable a_Table, int a_StartIndex, int a_EndIndex, ref int a_HighIndex, ref int a_LowIndex, ref double a_Min, ref double a_Max, ref double a_Open, ref double a_Close, ref double a_Low, ref double a_High)
        {

            if (a_Table == null || a_EndIndex < 0)
                return -1;

            if (a_Table.Rows.Count == 0)
                return -1;

            if (a_StartIndex < 0)
                a_StartIndex = 0;
            if (a_StartIndex > a_Table.Rows.Count - 1)
                a_StartIndex = a_Table.Rows.Count - 1;

            if (a_EndIndex > a_Table.Rows.Count - 1)
                a_EndIndex = a_Table.Rows.Count - 1;

            if (a_StartIndex > a_EndIndex)
                return -1;

            DataRow row = a_Table.Rows[a_StartIndex];
            double high = Convert.ToDouble(row["고가"]);
            double low = Convert.ToDouble(row["저가"]);
            double open = Convert.ToDouble(row["시가"]);

            //double max = open;
            //double min = open;
            a_Min = open;
            a_Max = open;
            for (int i = a_StartIndex; i <= a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                high = Convert.ToDouble(row["고가"]);
                low = Convert.ToDouble(row["저가"]);
                if (high > a_Max)
                {
                    a_Max = high;
                    a_HighIndex = i;
                }
                if (low < a_Min)
                {
                    a_Min = low;
                    a_LowIndex = i;
                }
                if (i == a_EndIndex)
                {
                    a_Close = Convert.ToDouble(row["종가"]);
                    a_High = high;
                    a_Low = low;
                    a_Open = Convert.ToDouble(row["시가"]);
                }
            }

            return Math.Max(a_HighIndex, a_LowIndex);
        }


        public static int FindMinMax(DataTable a_Table, int a_StartIndex, int a_EndIndex, ref double a_Min, ref double a_Max)
        {

            if (a_Table == null || a_EndIndex < 0)
                return -1;

            if (a_Table.Rows.Count == 0)
                return -1;

            if (a_StartIndex < 0)
                a_StartIndex = 0;
            if (a_StartIndex > a_Table.Rows.Count - 1)
                a_StartIndex = a_Table.Rows.Count - 1;

            if (a_EndIndex > a_Table.Rows.Count - 1)
                a_EndIndex = a_Table.Rows.Count - 1;

            if (a_StartIndex > a_EndIndex)
                return -1;

            DataRow row = a_Table.Rows[a_StartIndex];
            double high = Convert.ToDouble(row["고가"]);
            double low = Convert.ToDouble(row["저가"]);
            double open = Convert.ToDouble(row["시가"]);

            //double max = open;
            //double min = open;
            a_Min = open;
            a_Max = open;
            for (int i = a_StartIndex; i <= a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                high = Convert.ToDouble(row["고가"]);
                low = Convert.ToDouble(row["저가"]);
                if (high > a_Max)
                {
                    a_Max = high;
                }
                if (low < a_Min)
                {
                    a_Min = low;
                }
            }

            return 1;
        }

        public static int InRangeCount(DataTable a_Table, int a_StartIndex, int a_EndIndex, double a_Val, int a_Mode)
        {

            if (a_Table == null || a_EndIndex < 0)
                return -1;

            if (a_Table.Rows.Count == 0)
                return -1;

            if (a_StartIndex < 0)
                a_StartIndex = 0;
            if (a_StartIndex > a_Table.Rows.Count - 1)
                a_StartIndex = a_Table.Rows.Count - 1;

            if (a_EndIndex > a_Table.Rows.Count - 1)
                a_EndIndex = a_Table.Rows.Count - 1;

            if (a_StartIndex > a_EndIndex)
                return -1;

            DataRow row = a_Table.Rows[a_StartIndex];
            double high = Convert.ToDouble(row["고가"].ToString());
            double low = Convert.ToDouble(row["저가"].ToString());

            string strHigh = (a_Val + GlobalVar.ErrorRange).ToString("F2");
            string strLow = (a_Val - GlobalVar.ErrorRange).ToString("F2");
            double highLimit = Convert.ToDouble(strHigh);
            double lowLimit = Convert.ToDouble(strLow);

            int count = 0;
            for (int i = a_StartIndex; i <= a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                high = Convert.ToDouble(row["고가"].ToString());
                low = Convert.ToDouble(row["저가"].ToString());
                if (a_Mode == GlobalVar.HighTarget)
                {
                    if (high <= highLimit && high >= lowLimit)
                        count++;
                }
                if (a_Mode == GlobalVar.LowTarget)
                {
                    if (low <= highLimit && low >= lowLimit)
                        count++;
                }
            }

            return count;
        }

        public static int InRangeCount(DataTable a_Table, int a_StartIndex, int a_EndIndex, double a_Val, int a_Mode, double a_ER, ref int a_MaxTimeGap)
        {

            if (a_Table == null || a_EndIndex < 0)
                return -1;

            if (a_Table.Rows.Count == 0)
                return -1;

            if (a_StartIndex < 0)
                a_StartIndex = 0;
            if (a_StartIndex > a_Table.Rows.Count - 1)
                a_StartIndex = a_Table.Rows.Count - 1;

            if (a_EndIndex > a_Table.Rows.Count - 1)
                a_EndIndex = a_Table.Rows.Count - 1;

            if (a_StartIndex > a_EndIndex)
                return -1;

            DataRow row = a_Table.Rows[a_StartIndex];
            double high = Convert.ToDouble(row["고가"].ToString());
            double low = Convert.ToDouble(row["저가"].ToString());

            string strHigh = (a_Val + a_ER).ToString("F2");
            string strLow = (a_Val - a_ER).ToString("F2");
            double highLimit = Convert.ToDouble(strHigh);
            double lowLimit = Convert.ToDouble(strLow);

            int count = 0;
            bool begin = false;
            int beginIndex = 0;
            int lastIndex = 0;
            for (int i = a_StartIndex; i <= a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                high = Convert.ToDouble(row["고가"].ToString());
                low = Convert.ToDouble(row["저가"].ToString());
                if (a_Mode == GlobalVar.HighTarget)
                {
                    if (high <= highLimit && high >= lowLimit)
                    {
                        if (begin == false)
                        {
                            beginIndex = i;
                            begin = true;
                        }
                        lastIndex = i;
                        count++;
                    }
                }
                if (a_Mode == GlobalVar.LowTarget)
                {
                    if (low <= highLimit && low >= lowLimit)
                    {
                        if (begin == false)
                        {
                            beginIndex = i;
                            begin = true;
                        }
                        lastIndex = i;
                        count++;
                    }
                }
            }

            a_MaxTimeGap = (lastIndex - beginIndex);

            if (count >= 3 && a_MaxTimeGap >= 4)
            {
                int p = 0;
                p = p + 1;
            }

            return count;
        }

        public static int FindBreakUpDown(DataTable a_Table, int a_StartIndex, int a_EndIndex, double a_CompVal, ref double a_Close, ref double a_Low, ref double a_High)
        {

            if (a_Table == null || a_EndIndex < 0)
                return GlobalVar.BreakNone;

            if (a_StartIndex < 0)
                a_StartIndex = 0;
            if (a_StartIndex > a_Table.Rows.Count - 1)
                a_StartIndex = a_Table.Rows.Count - 1;

            if (a_EndIndex > a_Table.Rows.Count - 1)
                a_EndIndex = a_Table.Rows.Count - 1;

            if (a_StartIndex > a_EndIndex)
                return GlobalVar.BreakNone;

            DataRow row = a_Table.Rows[a_StartIndex];
            double high = Convert.ToDouble(row["고가"]);
            double low = Convert.ToDouble(row["저가"]);
            double open = Convert.ToDouble(row["시가"]);

            //double max = open;
            //double min = open;
            double a_Min = open;
            double a_Max = open;
            for (int i = a_StartIndex; i <= a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                high = Convert.ToDouble(row["고가"]);
                low = Convert.ToDouble(row["저가"]);
                if (high > a_Max)
                {
                    a_Max = high;
                }
                if (low < a_Min)
                {
                    a_Min = low;
                }
                if (i == a_EndIndex)
                {
                    a_Close = Convert.ToDouble(row["종가"]);
                    a_High = high;
                    a_Low = low;
                }
            }

            if (a_Max >= a_CompVal && a_Min <= a_CompVal)
            {
                if (a_Close < a_CompVal)
                {
                    return GlobalVar.BreakDown;
                }
                else if (a_Close > a_CompVal)
                {
                    return GlobalVar.BreakUp;
                }
            }

            return GlobalVar.BreakNone;
        }


        public static int FindBreakUpDown(DataTable a_Table, int a_StartIndex, int a_EndIndex, double a_CompVal)
        {

            if (a_Table == null || a_EndIndex < 0)
                return GlobalVar.BreakNone;

            if (a_Table.Rows.Count == 0)
                return GlobalVar.BreakNone;

            if (a_StartIndex < 0)
                a_StartIndex = 0;
            if (a_StartIndex > a_Table.Rows.Count - 1)
                a_StartIndex = a_Table.Rows.Count - 1;

            if (a_EndIndex > a_Table.Rows.Count - 1)
                a_EndIndex = a_Table.Rows.Count - 1;

            if (a_StartIndex > a_EndIndex)
                return GlobalVar.BreakNone;

            DataRow row = a_Table.Rows[a_StartIndex];
            double high = Convert.ToDouble(row["고가"]);
            double low = Convert.ToDouble(row["저가"]);
            double open = Convert.ToDouble(row["시가"]);

            //double max = open;
            //double min = open;
            double a_Min = open;
            double a_Max = open;
            double close = 0.0;
            int highIndex = 0;
            int lowIndex = 0;
            for (int i = a_StartIndex; i <= a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                high = Convert.ToDouble(row["고가"]);
                low = Convert.ToDouble(row["저가"]);
                if (high > a_Max)
                {
                    a_Max = high;
                    highIndex = i;
                }
                if (low < a_Min)
                {
                    a_Min = low;
                    lowIndex = i;
                }
                if (i == a_EndIndex)
                {
                    close = Convert.ToDouble(row["종가"]);
                    high = Convert.ToDouble(row["고가"]);
                    low = Convert.ToDouble(row["저가"]);
                }
            }

            if (a_Max >= a_CompVal && a_Min <= a_CompVal)
            {
                if (highIndex > lowIndex)
                {
                    if (a_Max > a_CompVal)
                    {
                        if (close < a_CompVal)
                            return GlobalVar.BreakDownFromUp;
                        else if (close > a_CompVal)
                            return GlobalVar.BreakUp;
                    }
                }
                else if (lowIndex > highIndex)
                {
                    if (a_Min < a_CompVal)
                    {
                        if (close > a_CompVal)
                            return GlobalVar.BreakUpFromDown;
                        else if (close < a_CompVal)
                            return GlobalVar.BreakDown;
                    }
                }
                else
                {
                    if (close < a_CompVal)
                    {
                        return GlobalVar.BreakDown;
                    }
                    else if (close > a_CompVal)
                    {
                        return GlobalVar.BreakUp;
                    }
                }
            }

            return GlobalVar.BreakNone;
        }

        public static bool IsLastSignalSame(PriceSignalList a_SignalList, int a_SignalType)
        {
            if (a_SignalList == null)
                return false;

            int signalCount = a_SignalList.Count;
            if (signalCount == 0)
            {
                return false;
            }

            EasyTrader.Signal.PriceSignal prevSignal = a_SignalList[signalCount - 1];
            if (prevSignal.Type == a_SignalType)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        // 신호가 동시간 대에 있는지 초의 차이를 통해서 확인한다.
        public static bool IsLastSignalSameTime(PriceSignalList a_SignalList, int a_SignalTime)
        {
            if (a_SignalList == null)
                return false;

            int signalCount = a_SignalList.Count;
            if (signalCount == 0)
            {
                return false;
            }

            EasyTrader.Signal.PriceSignal prevSignal = a_SignalList[signalCount - 1];
            DateTime now = DateTime.Now;
            string curTime = a_SignalTime.ToString();
            string prevTime = prevSignal.Time.ToString();
            if (curTime.Length < 5 || prevTime.Length < 5)
            {
                GlobalVar.WriteLog(GlobalVar.TimeFormatError);
                return false;
            }
            string curSecond = curTime.Substring(curTime.Length - 2, 2);
            string prevSecond = prevTime.Substring(prevTime.Length - 2, 2);
            string curMin = curTime.Substring(curTime.Length - 4, 2);
            string prevMin = prevTime.Substring(prevTime.Length - 4, 2);
            int curSecondVal = Convert.ToInt32(curSecond);
            int prevSecondVal = Convert.ToInt32(prevSecond);
            int curMinVal = Convert.ToInt32(curMin);
            int prevMinVal = Convert.ToInt32(prevMin);
            string curHour = curTime.Substring(0, curTime.Length - 4);
            string prevHour = prevTime.Substring(0, prevTime.Length - 4);
            int curHourVal = Convert.ToInt32(curHour);
            int prevHourVal = Convert.ToInt32(prevHour);
            DateTime prevTimeVal = new DateTime(now.Year, now.Month, now.Day, prevHourVal, prevMinVal, prevSecondVal);
            DateTime curTimeVal = new DateTime(now.Year, now.Month, now.Day, curHourVal, curMinVal, curSecondVal);
            TimeSpan curSpan = curTimeVal - prevTimeVal;
            double tSeconds = curSpan.TotalSeconds;

            // 시간차이가 60초 안이면 동시간대에 발생한 것으로 한다.
            if (Math.Abs(tSeconds) < GlobalVar.MinSignalInterval)
                return true;
            else // 시간차이가 60초 이상되었을 때는 다른 신호로 본다.
                return false;
        }


        public static bool IsLastSignalSameMinute(PriceSignalList a_SignalList, int a_SignalTime)
        {
            if (a_SignalList == null)
                return false;

            int signalCount = a_SignalList.Count;
            if (signalCount == 0)
            {
                return false;
            }

            EasyTrader.Signal.PriceSignal prevSignal = a_SignalList[signalCount - 1];
            if (prevSignal.OptSigTime == a_SignalTime)
                return true;
            else
                return false;
        }

        public static EasyTrader.Signal.PriceSignal CheckAddSignal(PriceSignalList a_SignalList, EasyTrader.Signal.PriceSignal a_Signal)
        {
            if (a_Signal == null || a_SignalList == null)
                return null;
            // 같은 종류의 신호나 같은 시간(분)에 발생한 신호는 받아 들이지 않는다.
            // 같은 시간 같은 종류의 신호는 받아들이지 않는다. 
            if (IsLastSignalSame(a_SignalList, a_Signal.Type) == false && IsLastSignalSameMinute(a_SignalList, a_Signal.OptSigTime) == false)
            {
                EasyTrader.Signal.PriceSignal signal = a_Signal.Clone();
                AddSignal(a_SignalList, signal);
                return signal;
            }

            return null;
        }

        public static void AddSignal(PriceSignalList a_SignalList, EasyTrader.Signal.PriceSignal a_Signal)
        {
            if (a_SignalList == null)
                return;

            int signalCount = a_SignalList.Count;
            if (signalCount == 0)
            {
                a_SignalList.Add(a_Signal);
                return;
            }

            EasyTrader.Signal.PriceSignal prevSignal = a_SignalList[signalCount - 1];
            if (prevSignal.Type != a_Signal.Type)
            {
                a_SignalList.Add(a_Signal);
            }
        }

        public static double CalcOptMargin(double a_Val)
        {
            double mulVal = a_Val;
            double margin = 0.0;
            if (mulVal >= 7.0)
                margin = mulVal * 0.01;
            if (mulVal < 7.0 && mulVal >= 5.0)
                margin = mulVal * 0.02;
            else if (mulVal < 5.0 && mulVal >= 4.0)
                margin = mulVal * 0.03;
            else if (mulVal < 4.0 && mulVal >= 3.0)
                margin = mulVal * 0.04;
            else if (mulVal < 3.0 && mulVal >= 2.0)
                margin = mulVal * 0.045;
            else if (mulVal < 2.0 && mulVal >= 1.0)
                margin = mulVal * 0.05;
            else
                margin = mulVal * 0.06;

            return margin;
        }

        public static void ClearAllAutoOrder()
        {
            for (int i = 0; i < GlobalVar.SysNameArray.Length; i++)
            {
                ClearAutoOrder(i);
            }
        }

        public static void ClearAutoOrder(int a_SysType)
        {
            string selText = "False";
            bool autoOrder = false;

            string regSubkey = "Software\\EasyTrader\\SysVar\\JisuWaveHogaSummitSysVar";
            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\JisuWaveHogaSummitSysVar";
                JisuWaveHogaSummitSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\JisuWaveSysVar";
                JisuWaveSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\HogaWaveSysVar";
                HogaWaveSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\HogaSquareOccSysVar";
                HogaSquareOccSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\HogaSummitSysVar";
                HogaSummitSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutSquareOcc)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\CallPutSquareOccSysVar";
                CallPutSquareOccSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypePureHogaSummit)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\PureHogaSummitSysVar";
                PureHogaSummitSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeLooseHogaSummit)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\LooseHogaSummitSysVar";
                LooseHogaSummitSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutInvDiv)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\CallPutInvDivSysVar";
                CallPutInvDivSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeTipAttack)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\TipAttackSysVar";
                TipAttackSysVar.AutoOrder = autoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeOptPrice)
            {
                regSubkey = "Software\\EasyTrader\\SysVar\\OptPriceSysVar";
                OptPriceSysVar.AutoOrder = autoOrder;
            }

            RegistryKey rk = Registry.CurrentUser.OpenSubKey(regSubkey, true);
            // 없으면 서브키를 만든다.
            if (rk == null)
            {
                // 해당이름으로 서브키 생성
                rk = Registry.CurrentUser.CreateSubKey(regSubkey);
            }

            // 서브키 아래 값 쓰기
            rk.SetValue("AutoOrder", selText);
        }



        public static int CalcMaxDayIndex()
        {
            int totalMin = 0;
            int hour = DayCloseHour - (DayOpenTime + 1);
            totalMin += hour * 60;
            int min = 60 - DayOpenMin + DayCloseMin - 11;
            totalMin += min;
            return totalMin;
        }
        public static int DayOpenTimeEx()
        {
            string openTime = DayOpenTime.ToString();
            openTime += "00";
            return Convert.ToInt32(openTime);
        }

        public static int PreMarketTime()
        {
            int time = DayOpenTime - 1;
            string openTime = time.ToString();
            openTime += "59";
            return Convert.ToInt32(openTime);
        }
        // 제라의 공식 (요일 리턴 0:일, 1:월, 2:화, 3:수, 4:목, 5:금, 6:토) 
        // yy는 년도의 뒷 두자리, mm은 월, dd는 일 
        static int ZellersCongruence(int yy, int mm, int dd)
        {
            if (mm < 3)
            {
                --yy;
                mm += 12;
            }
            return (105 + 5 * yy / 4 + 26 * (mm + 1) / 10 + dd - 1) % 7;
        }

        // 이 함수는 다운로드 받은 데이터를 파일에 저장합니다.
        public static bool SaveArrayData(string a_FileName, object[] a_arVal)
        {
            // 기존 파일이 있으면 지워준다.
            if (File.Exists(a_FileName))
            {
                File.Delete(a_FileName);
            }

            // 새로운 파일을 만든다.
            FileStream fs = new FileStream(a_FileName, FileMode.Create);
            // 스트림 쓰기 객체를 생성한다.
            StreamWriter sw = new StreamWriter(fs);
            string data = "";
            for (int i = 0; i < a_arVal.Length; i++)
            {
                data += a_arVal[i].ToString();
                if (i != (a_arVal.Length - 1))
                    data += ",";
            }
            sw.WriteLine(data);

            // 스트림 쓰기 객체를 닫아 준다.
            sw.Close();

            return true;
        }

        // 주어진 날짜로 선물 코드 값을 만들어 반환한다.
        public static string GetFutureCode(DateTime t)
        {
            string str = "";
            string year = (t.Year - 1941).ToString();
            string month = "";
            int day = t.Day;
            int head = ZellersCongruence(t.Year, t.Month, 1);

            // 이번달 1일의 요일     
            bool thur2over = false;
            // 목요일이 두번 지났으면 TRUE       
            if (day < 9)
                thur2over = false;
            else if (day > 14)
                thur2over = true;
            else
            {
                if (head <= 4)
                {
                    if (13 - head > day)
                        thur2over = false;
                    else
                        thur2over = true;
                }
                else
                {
                    if (20 - head > day)
                        thur2over = false;
                    else
                        thur2over = true;
                }
            }

            switch (t.Month)
            {
                case 1:
                case 2:
                    month = "3";
                    break;
                case 3:
                    if (thur2over)
                        month = "6";
                    else
                        month = "3";
                    break;
                case 4:
                case 5:
                    month = "6";
                    break;
                case 6:
                    if (thur2over)
                        month = "9";
                    else
                        month = "6";
                    break;
                case 7:
                case 8:
                    month = "9";
                    break;
                case 9:
                    if (thur2over)
                        month = "C";
                    else
                        month = "9";
                    break;
                case 10:
                case 11:
                    month = "C";
                    break;
                case 12:
                    if (thur2over)
                    {
                        month = "3";
                        year = (t.Year - 1940).ToString();
                    }
                    else
                        month = "C";
                    break;
            }
            str = ("101" + year + month + "000");

            return str;
        }

        // 현재 날짜의 선물 코드 값을 만들어 반환한다.
        public static string GetCurFutureCode()
        {
            DateTime t = DateTime.Now;
            string str = "";
            string year = (t.Year - 1941).ToString();
            string month = "";
            int day = t.Day;
            int head = ZellersCongruence(t.Year, t.Month, 1);

            // 이번달 1일의 요일     
            bool thur2over = false;
            // 목요일이 두번 지났으면 TRUE       
            if (day < 9)
                thur2over = false;
            else if (day > 14)
                thur2over = true;
            else
            {
                if (head <= 4)
                {
                    if (13 - head > day)
                        thur2over = false;
                    else
                        thur2over = true;
                }
                else
                {
                    if (20 - head > day)
                        thur2over = false;
                    else
                        thur2over = true;
                }
            }

            switch (t.Month)
            {
                case 1:
                case 2:
                    month = "3";
                    break;
                case 3:
                    if (thur2over)
                        month = "6";
                    else
                        month = "3";
                    break;
                case 4:
                case 5:
                    month = "6";
                    break;
                case 6:
                    if (thur2over)
                        month = "9";
                    else
                        month = "6";
                    break;
                case 7:
                case 8:
                    month = "9";
                    break;
                case 9:
                    if (thur2over)
                        month = "C";
                    else
                        month = "9";
                    break;
                case 10:
                case 11:
                    month = "C";
                    break;
                case 12:
                    if (thur2over)
                    {
                        month = "3";
                        year = (t.Year - 1940).ToString();
                    }
                    else
                        month = "C";
                    break;
            }
            str = ("101" + year + month + "000");

            return str;
        }


        // Log file name
        private static string m_LogFileName = "Log.txt";

        public static string LogFileName
        {
            get { return GlobalVar.m_LogFileName; }
            set { GlobalVar.m_LogFileName = value; }
        }

        public static void WriteLog(string a_LogText)
        {
            DateTime now = DateTime.Now;
            int year = now.Year;
            int month = now.Month;
            int day = now.Day;
            string fileName = Directory.GetCurrentDirectory();
            fileName += "\\";
            fileName += year.ToString() + "_";
            fileName += month.ToString() + "_";
            fileName += day.ToString() + "_";
            fileName += m_LogFileName;
            
            using (StreamWriter writer = new StreamWriter(fileName, true))
            {
                string curDate = now.Year.ToString() + ":";
                curDate += now.Month.ToString() + ":";
                curDate += now.Day.ToString() + ":";
                curDate += now.Hour.ToString() + ":";
                curDate += now.Minute.ToString() + ":";
                curDate += now.Second.ToString() + ": ";
                curDate += a_LogText;
                writer.WriteLine(curDate);
            }
        }

        public static void WriteLogWithFileName(string a_LogText, string a_FileName)
        {
            DateTime now = DateTime.Now;
            int year = now.Year;
            int month = now.Month;
            int day = now.Day;
            string fileName = Directory.GetCurrentDirectory();
            fileName += "\\";
            fileName += year.ToString() + "_";
            fileName += month.ToString() + "_";
            fileName += day.ToString() + "_";
            fileName += a_FileName;

            using (StreamWriter writer = new StreamWriter(fileName, true))
            {
                string curDate = now.Year.ToString() + ":";
                curDate += now.Month.ToString() + ":";
                curDate += now.Day.ToString() + ":";
                curDate += now.Hour.ToString() + ":";
                curDate += now.Minute.ToString() + ":";
                curDate += now.Second.ToString() + ": ";
                curDate += a_LogText;
                writer.WriteLine(curDate);
            }
        }

        public static void WriteLog(string a_CurTime, string a_LogText)
        {
            using (StreamWriter writer = new StreamWriter(m_LogFileName, true))
            {
                string logText = a_CurTime;
                logText += ":" + a_LogText;
                writer.WriteLine(logText);
            }
        }

        public static int CalcCurIndex(string a_CurTime)
        {
            if (a_CurTime == "0")
                return 0;
            string minText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 2);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            if (curHour < DayOpenTime)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            return result + minuteIndex;
        }

        public static int DayIndex(string a_CurTime)
        {
            if (a_CurTime == "0")
                return 0;
            string minText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 2);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            if (curHour < DayOpenTime)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            return Math.Min(MaxDayIndex, result + minuteIndex);
            /*
            if (a_CurTime == "0")
                return 0;
            string minText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 2);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            if (curHour < DayOpenTime - 1)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime + 1;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            return Math.Min(MaxDayIndex + 1, Math.Max(result + minuteIndex - 59, 0));
             */
        }


        public static int DayIndex(string a_CurTime, int a_Cycle)
        {
            if (a_CurTime == "0")
                return 0;
            string minText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 2);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            if (curHour < DayOpenTime)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            result += minuteIndex;
            double total = Convert.ToDouble(result);
            total = total / Convert.ToDouble(a_Cycle);
            return Math.Min(MaxDayIndex, (int)total);
        }


        public static int DayIndexWithSec(string a_CurTime)
        {
            if (a_CurTime == "0")
                return 0;
            string minText = a_CurTime.Substring(a_CurTime.Length - 4, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 4);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            if (curHour < DayOpenTime - 1)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime + 1;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            return Math.Min(MaxDayIndex + 1, Math.Max(result + minuteIndex - 59, 0));
        }

        public static int GetServerSec(string a_CurTime)
        {
            if (a_CurTime == "0")
                return 0;
            string secText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            return Convert.ToInt32(secText);
        }

        public static int HogaDayIndex(string a_CurTime)
        {
            if (a_CurTime == "0")
                return 0;
            string minText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 2);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            if (curHour < DayOpenTime - 1)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime + 1;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            return Math.Min(MaxDayIndex + 1, Math.Max(result + minuteIndex - 59, 0));
        }

        public static int NightIndex(string a_CurTime)
        {
            if (a_CurTime == "0")
                return 0;

            string minText = a_CurTime.Substring(a_CurTime.Length - 2, 2);
            string hourText = a_CurTime.Substring(0, a_CurTime.Length - 2);
            int curHour = Convert.ToInt32(hourText);
            int curMinute = Convert.ToInt32(minText);

            int hourIndex = 0;
            int minuteIndex = curMinute;
            if (curHour >= NightOpenTime)
            {
                hourIndex = curHour - NightOpenTime;
            }
            else
            {
                hourIndex = curHour + (24 - NightOpenTime);
            }
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            // 시뮬레이션 모드 일 때는 모든 종일 데이터 개수를 넣어 준다.
            if (GlobalVar.OperationMode == OperationModeSimul)
                result = MaxNightIndex;
            else
                result = Math.Min(MaxNightIndex, result + minuteIndex);
            return result;
        }

        public static int DayIndex()
        {
            DateTime now = DateTime.Now;
            int curHour = now.Hour;
            int curMinute = now.Minute;

            if (curHour < DayOpenTime)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            // 시뮬레이션 모드 일 때는 모든 종일 데이터 개수를 넣어 준다.
            if (GlobalVar.OperationMode == OperationModeSimul)
                result = MaxDayIndex;
            else
                result = Math.Min(MaxDayIndex, result + minuteIndex);
            return result;
            /*
            DateTime now = DateTime.Now;
            int curHour = now.Hour;
            int curMinute = now.Minute;

            if (curHour < DayOpenTime - 1)
                return 0;
            int hourIndex = 0;
            hourIndex = curHour - DayOpenTime + 1;
            int minuteIndex = curMinute;
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            return Math.Min(MaxDayIndex + 1, Math.Max(result + minuteIndex - 59, 0));
             */
        }

        public static int NightIndex()
        {
            DateTime now = DateTime.Now;
            int curHour = now.Hour;
            int curMinute = now.Minute;
            int hourIndex = 0;
            int minuteIndex = curMinute;
            if (curHour >= NightOpenTime)
            {
                hourIndex = curHour - NightOpenTime;
            }
            else
            {
                hourIndex = curHour + (24 - NightOpenTime);
            }
            if (hourIndex < 0)
                hourIndex = 0;
            if (minuteIndex < 0)
                minuteIndex = 0;
            int result = hourIndex * 60;
            // 시뮬레이션 모드 일 때는 모든 종일 데이터 개수를 넣어 준다.
            if (GlobalVar.OperationMode == OperationModeSimul)
                result = MaxNightIndex;
            else
                result = Math.Min(MaxNightIndex, result + minuteIndex);
            return result;
        }

        public static int DateToInt()
        {
            DateTime curTime = DateTime.Now;
            string curDate = curTime.Year.ToString();
            if (curTime.Month < 10)
                curDate += ("0" + curTime.Month.ToString());
            else
                curDate += curTime.Month.ToString();
            if (curTime.Day < 10)
            {
                curDate += ("0" + curTime.Day.ToString());
            }
            else
            {
                curDate += curTime.Day.ToString();
            }

            return Convert.ToInt32(curDate);
        }

        public static int PreDateToInt()
        {
            DateTime curTime = DateTime.Now.AddDays(-1);
            string curDate = curTime.Year.ToString();
            if (curTime.Month < 10)
                curDate += ("0" + curTime.Month.ToString());
            else
                curDate += curTime.Month.ToString();
            if (curTime.Day < 10)
            {
                curDate += ("0" + curTime.Day.ToString());
            }
            else
            {
                curDate += curTime.Day.ToString();
            }

            return Convert.ToInt32(curDate);
        }

        // 차트의 인덱스를 시간으로 변환해 준다.
        // 9:00 -> 0, 9:01->1 순서로 간다.
        public static int DayIndexToTime(int a_Index)
        {
            int hour = (int)(a_Index / 60);
            hour = hour + DayOpenTime;
            int min = a_Index % 60;
            string curTime = hour.ToString();

            if (min < 10)
            {
                curTime += ("0" + min.ToString());
            }
            else
            {
                curTime += min.ToString();
            }

            return Convert.ToInt32(curTime);
        }

        public static int DayIndexToTimeEx(int a_Index)
        {
            int hour = (int)(a_Index / 60);
            hour = hour + DayOpenTime;
            int min = a_Index % 60;
            string curTime = hour.ToString();

            if (min < 10)
            {
                curTime += ("0" + min.ToString());
            }
            else
            {
                curTime += min.ToString();
            }

            curTime += "00";

            return Convert.ToInt32(curTime);
        }

        // 차트의 인덱스를 시간으로 변환해 준다.
        // 8:00 -> 0, 8:01->1 순서로 간다.
        public static int HogaDayIndexToTime(int a_Index)
        {
            int hour = (int)(a_Index / 60);
            hour = hour + DayOpenTime;
            int min = a_Index % 60;
            string curTime = hour.ToString();

            if (min < 10)
            {
                curTime += ("0" + min.ToString());
            }
            else
            {
                curTime += min.ToString();
            }

            return Convert.ToInt32(curTime);
        }

        // 차트의 인덱스를 시간으로 변환해 준다.
        // 9:00 -> 0, 9:01->1 순서로 간다.
        public static int NightIndexToTime(int a_Index)
        {
            int hour = (int)(a_Index / 60);
            if (hour < 6)
            {
                hour += NightOpenTime;
            }
            else
            {
                hour -= (24 - NightOpenTime);
            }
            int min = a_Index % 60;
            string curTime = hour.ToString();

            if (min < 10)
            {
                curTime += ("0" + min.ToString());
            }
            else
            {
                curTime += min.ToString();
            }

            return Convert.ToInt32(curTime);
        }

        public static int DateToInt(DateTime curTime)
        {
            string curDate = curTime.Year.ToString();
            if (curTime.Month < 10)
                curDate += ("0" + curTime.Month.ToString());
            else
                curDate += curTime.Month.ToString();
            if (curTime.Day < 10)
            {
                curDate += ("0" + curTime.Day.ToString());
            }
            else
            {
                curDate += curTime.Day.ToString();
            }

            return Convert.ToInt32(curDate);
        }

        public static int TimeToInt(int a_Hour, int a_Min)
        {
            string strCurTime = a_Hour.ToString();

            if (a_Min < 10)
            {
                strCurTime += ("0" + a_Min.ToString());
            }
            else
            {
                strCurTime += a_Min.ToString();
            }

            return Convert.ToInt32(strCurTime);
        }

        public static int GetCurTime()
        {
            DateTime curTime = DateTime.Now;
            string strCurTime = curTime.Hour.ToString();

            if (curTime.Minute < 10)
            {
                strCurTime += ("0" + curTime.Minute.ToString());
            }
            else
            {
                strCurTime += curTime.Minute.ToString();
            }

            if (curTime.Second < 10)
            {
                strCurTime += ("0" + curTime.Second.ToString());
            }
            else
            {
                strCurTime += curTime.Second.ToString();
            }

            return Convert.ToInt32(strCurTime);
        }

        public static int TimeToInt()
        {
            DateTime curTime = DateTime.Now;
            string strCurTime = curTime.Hour.ToString();

            if (curTime.Minute < 10)
            {
                strCurTime += ("0" + curTime.Minute.ToString());
            }
            else
            {
                strCurTime += curTime.Minute.ToString();
            }

            return Convert.ToInt32(strCurTime);
        }

        public static int TimeToIntEx()
        {
            DateTime curTime = DateTime.Now;
            string strCurTime = curTime.Hour.ToString();

            if (curTime.Minute < 10)
            {
                strCurTime += ("0" + curTime.Minute.ToString());
            }
            else
            {
                strCurTime += curTime.Minute.ToString();
            }

            if (curTime.Second < 10)
            {
                strCurTime += ("0" + curTime.Second.ToString());
            }
            else
            {
                strCurTime += curTime.Second.ToString();
            }

            return Convert.ToInt32(strCurTime);
        }

        public static void PlayOrderSellSound()
        {
            if (EnableSound == false)
                return;
            string path = Directory.GetCurrentDirectory();
            path += "\\" + "OrderSell.wav";
            System.Media.SoundPlayer simpleSound = new System.Media.SoundPlayer(path);
            simpleSound.Play();
        }

        public static void PlaySignalBuySound()
        {
            if (EnableSound == false)
                return;
            string path = Directory.GetCurrentDirectory();
            path += "\\" + "SignalBuy.wav";
            System.Media.SoundPlayer simpleSound = new System.Media.SoundPlayer(path);
            simpleSound.Play();
        }

        public static void PlaySignalSellSound()
        {
            if (EnableSound == false)
                return;
            string path = Directory.GetCurrentDirectory();
            path += "\\" + "SignalSell.wav";
            System.Media.SoundPlayer simpleSound = new System.Media.SoundPlayer(path);
            simpleSound.Play();
        }

        public static void PlayOrderBuySound()
        {
            if (EnableSound == false)
                return;
            string path = Directory.GetCurrentDirectory();
            path += "\\" + "OrderBuy.wav";
            System.Media.SoundPlayer simpleSound = new System.Media.SoundPlayer(path);
            simpleSound.Play();
        }

        #endregion
    }
}
